/**
 * 有效括号问题
 * 描述：给定一个只包含(),{},[]的字符串，判断字符型是否有效
*/

const isValid = (s) => {
    if (s % 2 === 1) return false
    const paris = {
        "}": "{",
        ")": "(",
        "]": "["
    }
    const charts = []
    for (const chart of s) {
        if (paris[chart]) {
            if (charts.pop() !== paris[chart]) return false
        } else {
            charts.push(chart)
        }
    }
    return charts.length === 0
}
console.log(isValid('{())}'))



/**
 * 每日温度问题
*/



const temp = (arr) => {
    const result = new Array(arr.length).fill(0)
    const stack = []
    for (let i = 0; i < arr.length; i++) {
        while (stack.length && arr[i] > arr[stack[stack.length - 1]]) {
            const prevIndex = stack.pop()
            result[prevIndex] = i - prevIndex
        }
        stack.push(i)
    }
    return result
}

console.log(temp([73,74,75,71,69,72,76,73]))